<?php

namespace App\Console\Commands;

use App\Ant\Excel\Imports\ArchiveImport;
use App\Models\Company\Archive;
use App\Models\Encyclopedia\Article;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use App\Models\Company\Task as TaskModel;

class Push extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'push:url';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Push Url';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Archive::with('region')->where('is_state', true)->chunk(200, function ($items) {
            $items->each(function ($item) {
                $url = $item->region->initials . '.mayiguan.com';
                $path = '/company/detail/' . $item->id;
                event(new \App\Events\Push($url, $path));
            });
        });

        Article::chunk(200, function ($items) {
            $items->each(function ($item) {
                $url = 'mayiguan.com';
                $path = '/baike/detail/' . $item->id;
                event(new \App\Events\Push($url, $path));
            });
        });
    }
}
